class_name DayNightCycleComponent
extends CanvasModulate


@export var initial_day : int = 1:
	set(day):
		initial_day = day
		DayNightCycleMgr.initial_day = day
		DayNightCycleMgr.set_initial_time()

@export var initial_hour : int = 12:
	set(hour):
		initial_hour = hour
		DayNightCycleMgr.initial_hour = hour
		DayNightCycleMgr.set_initial_time()

@export var initial_minute : int = 30:
	set(minute):
		initial_minute = minute
		DayNightCycleMgr.initial_minute = minute
		DayNightCycleMgr.set_initial_time()

@export var day_night_gradient_texture : GradientTexture1D

func _ready() -> void:
	DayNightCycleMgr.initial_day = initial_day
	DayNightCycleMgr.initial_hour = initial_hour
	DayNightCycleMgr.initial_minute = initial_minute
	
	DayNightCycleMgr.game_time.connect(on_game_time)

func on_game_time(time: float) -> void:
	var sample_value = 0.5 * (sin(time - PI * 0.5))
	color = day_night_gradient_texture.gradient.sample(sample_value)
